﻿Namespace SchoolClick.Controllers
    Public Class HomeController
        Inherits AuthorizeBaseController

        Function Index() As ActionResult
            Dim strRol As String = Roles.GetRolesForUser().SingleOrDefault
            Select Case strRol
                Case "ALU"
                    Return RedirectToAction("index", "Alumnos", New RouteValueDictionary(New With {.topmenu = "Alumno"}))
                Case "PRF"
                    Return RedirectToRoute("Route_ProfesoresHome")
                Case "ERA"
                    Return RedirectToRoute("Route_RegistroAcademicoHome")
            End Select
            Return View()
        End Function

        Function SignOut() As ActionResult
            FormsAuthentication.SignOut()
            Return RedirectToRoute("Default", New With {.controller = "Accounts", .action = "LogOn"})
        End Function

        <ConstructSubMenu()> _
        <Authorize(Roles:="ERA")> _
        Public Function Change_Password() As ActionResult
            Return View()
        End Function

        <ConstructSubMenu()> _
        <Authorize(Roles:="ALU")> _
        Public Function Change_Password_Alumno() As ActionResult
            Return View()
        End Function

        <ConstructSubMenu()> _
       <Authorize(Roles:="PRF")> _
        Public Function CamPassword() As ActionResult
            Return View()
        End Function

        <HttpGet()> _
        Function _validateIDUser(ID_Usuario As String) As JsonResult
            Dim db As New SchoolClickDAL
            If db.IUsuariosYRoles.IsExist(ID_Usuario) Then
                Return Json("Ya existe un usuario en el sistema con este nombre de usuario.", JsonRequestBehavior.AllowGet)
            Else
                Return Json(True, JsonRequestBehavior.AllowGet)
            End If
        End Function
    End Class
End Namespace
